package com.ruoyi.stuinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.stuinfo.domain.StudentActivityComprehensiveScore;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.stuinfo.domain.EduCommunication;
import com.ruoyi.stuinfo.service.IEduCommunicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 沟通记录Controller
 *
 * @author zc
 * @date 2025-05-15
 */
@RestController
@RequestMapping("/stuinfo/communication")
public class EduCommunicationController extends BaseController
{
    @Autowired
    private IEduCommunicationService eduCommunicationService;

    /**
     * 查询沟通记录列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:communication:list')")
    @GetMapping("/list")
    public TableDataInfo list(EduCommunication eduCommunication)
    {
        String teacherId=getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<EduCommunication> list = eduCommunicationService.selectEduCommunicationList(eduCommunication);
            return getDataTable(list);
        }
        else
        {
            //班主任
            teacherId=teacherId.replace("H", "");
            startPage();
            List<EduCommunication> list = eduCommunicationService.selectEduCommunicationList_handteacher(teacherId);
            return getDataTable(list);
        }
    }

    /**
     * 导出沟通记录列表
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:communication:export')")
    @Log(title = "沟通记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduCommunication eduCommunication)
    {

        String teacherId=getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            List<EduCommunication> list = eduCommunicationService.selectEduCommunicationList(eduCommunication);
            ExcelUtil<EduCommunication> util = new ExcelUtil<EduCommunication>(EduCommunication.class);
            util.exportExcel(response, list, "沟通记录数据");
        }
        else
        {
            //班主任
            teacherId=teacherId.replace("H", "");
            List<EduCommunication> list = eduCommunicationService.selectEduCommunicationList_handteacher(teacherId);
            ExcelUtil<EduCommunication> util = new ExcelUtil<EduCommunication>(EduCommunication.class);
            util.exportExcel(response, list, "沟通记录数据");
        }

    }

    /**
     * 获取沟通记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:communication:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eduCommunicationService.selectEduCommunicationById(id));
    }

    /**
     * 新增沟通记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:communication:add')")
    @Log(title = "沟通记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduCommunication eduCommunication)
    {
        return toAjax(eduCommunicationService.insertEduCommunication(eduCommunication));
    }

    /**
     * 修改沟通记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:communication:edit')")
    @Log(title = "沟通记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduCommunication eduCommunication)
    {
        return toAjax(eduCommunicationService.updateEduCommunication(eduCommunication));
    }

    /**
     * 删除沟通记录
     */
    @PreAuthorize("@ss.hasPermi('stuinfo:communication:remove')")
    @Log(title = "沟通记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eduCommunicationService.deleteEduCommunicationByIds(ids));
    }
}
